<template>
  <div>
    <FarmCardSkeleton v-if="loading" />
    <div class="farm-card" v-else>
      <div class="item">
        <div class="icon">
          <img :src="tokenIcon" />
          <img :src="quoteTokenIcon" />
        </div>
        <div class="rt">
          <div class="token">
            <span>{{ token.symbol }}-{{ quoteToken.symbol }}</span>
          </div>
          <div class="tag">
            <div>
              <i class="iconfont icon-stars"></i>
              <span>Core</span>
            </div>
            <div>
              <span>{{ multiplier }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="item">
        <span class="name">APR:</span>
        <div class="value">
          <span>41.21%</span>
          <i class="g-clickable iconfont icon-calculator"></i>
        </div>
      </div>
      <div class="item">
        <span class="name">Earn:</span>
        <div class="value">
          <span>{{ lpSymbol }} Provider Fees</span>
        </div>
      </div>
      <div class="item">
        <div class="earned">
          <span>{{ token.symbol }} EARNED</span>
          <span>0</span>
        </div>
        <div class="g-clickable g-card-button-gradient button">
          <span>Harvest</span>
        </div>
      </div>
      <div class="item">
        <span class="name"> {{ lpSymbol }} STAKED </span>
      </div>
      <div class="g-clickable g-card-button-gradient full-button">
        <span>Enabled Contract</span>
      </div>
      <div class="info">
        <!-- <div class="fold">
        <span>Hide</span>
        <i class="iconfont icon-arrow-up"></i>
      </div> -->
        <div class="sub">
          <span class="name">Stake</span>
          <a :href="`https://bscscan.com/address/${lpAddresses}`">
            <span>{{ token.symbol }}-{{ quoteToken.symbol }}</span>
            <i class="iconfont icon-share"></i>
          </a>
        </div>
        <div class="sub">
          <span class="name">Total Liquidity</span>
          <div class="tip">
            <span class="num"> {{ lpTotalSupply | formatNumber }} </span>
            <a href="#">
              <span>View Contract</span>
              <i class="iconfont icon-share"></i>
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import FarmCardSkeleton from "./FarmCardSkeleton";

export default {
  components: {
    FarmCardSkeleton,
  },
  props: {
    loading: {
      type: Boolean,
      default: false,
    },
    farm: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    token() {
      return (this.farm && this.farm.token) || {};
    },
    tokenIcon() {
      const { symbol } = this.token;
      return this.getTokenIcon(symbol);
    },
    quoteToken() {
      return (this.farm && this.farm.quoteToken) || {};
    },
    quoteTokenIcon() {
      const { symbol } = this.quoteToken;
      return this.getTokenIcon(symbol);
    },
    multiplier() {
      return (this.farm && this.farm.multiplier) || "0X";
    },
    lpSymbol() {
      return (this.farm && this.farm.lpSymbol) || 0;
    },
    poolWeight() {
      return (this.farm && this.farm.poolWeight) || 0;
    },
    lpAddresses() {
      return (this.farm && this.farm.lpAddresses) || 0;
    },
    lpTotalSupply() {
      return (this.farm && this.farm.lpTotalSupply) || 0;
    },
  },
  methods: {
    getTokenIcon(symbol) {
      return `https://assets.tokenswap.exchange/icon/${(symbol || '').toLowerCase()}.svg`;
    },
  },
};
</script>

<style lang="scss" scoped>
.farm-card {
  background-color: var(--card);
  padding: 30px;
  border-radius: 30px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;

  .icon {
    position: relative;
    img {
      border-radius: 50%;

      &:first-child {
        width: 32px;
        height: 32px;
      }

      &:last-child {
        width: 40px;
        height: 40px;
        position: absolute;
        left: 20px;
        top: 3px;
        z-index: 1;
      }
    }
  }
  .rt {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }
  .token {
    span {
      font-size: 18px;
      font-family: "Roboto Black";
    }
    margin-bottom: 12px;
  }
  .tag {
    display: flex;
    align-items: center;

    div {
      height: 28px;
      min-width: 40px;
      padding: 0 8px;
      border: 2px solid var(--border-color);
      box-sizing: border-box;
      border-radius: 12px;
      margin-left: 5px;

      display: flex;
      align-items: center;
      justify-content: center;

      i {
        font-size: 20px;
      }

      span {
        font-size: 10px;
        font-family: "Roboto Bold";
      }
    }
  }
  .name {
    font-size: 14px;
    font-family: "Roboto Regular";
    color: var(--color-content);
  }
  .value {
    font-size: 14px;
    font-family: "Roboto Medium";
    color: var(--color);

    i {
      font-size: 24px;
      margin-left: 5px;
    }
  }
  .earned {
    display: flex;
    flex-direction: column;
    align-items: flex-start;

    span {
      &:first-child {
        font-size: 14px;
        font-family: "Roboto Medium";
        color: var(--color-content);
        margin-bottom: 20px;
      }
      &:last-child {
        font-size: 16px;
        font-family: "Roboto Bold";
        color: var(--color);
      }
    }
  }
  .button {
    width: 150px;
    height: 60px;
    border-radius: 30px;

    span {
      font-size: 15px;
      font-family: "Roboto Bold";
      color: var(--color);
    }
  }
}

.full-button {
  height: 60px;
  font-size: 18px;
  color: var(--color-dark);
  border-radius: 30px;
  margin-top: -10px;

  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;

  span {
    font-size: 15px;
    font-family: "Roboto Bold";
    color: var(--color);
  }
}

.info {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin: 35px -30px 0;
  padding: 20px 30px 0;

  .fold {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;

    span {
      font-size: 15px;
      font-family: "Roboto Bold";
      color: var(--color);
    }

    i {
      font-size: 20px;
      margin-left: 15px;
    }
  }

  .sub {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-top: 10px;

    .name {
      font-size: 14px;
      font-family: "Roboto Regular";
      color: var(--color-content);
      margin-bottom: 18px;
    }

    .tip {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }

    .num {
      font-size: 14px;
      font-family: "Roboto Bold";
      color: var(--color);
      margin-bottom: 5px;
    }

    a {
      font-size: 14px;
      font-family: "Roboto Medium";
      color: var(--color-sky-blue);

      i {
        font-size: 18px;
      }
    }
  }
}
</style>
